<?php

namespace app\common\model;

use think\Model;

class Mailbox extends Model
{

    // 开启自动写入时间戳字段
//    protected $autoWriteTimestamp = 'int';
    // 定义时间戳字段名
    protected $createTime = 'createtime';


    public function getCreatetimeAttr($value)
    {
        $status = date('Y-m-d', $value);
        return $status;
    }

    public function getReplyTimeAttr($value)
    {
        $status = date('Y-m-d', $value);
        return $status;
    }


    public function getTypeAttr($value)
    {
        $status = ['chief'=>'首长信箱','lnspection'=>'纪委信箱','unit'=>'基层信箱','activity'=>'活动信箱'];
        return $status[$value];
    }

    public function getIsAnonymityAttr($value)
    {
        $status = ['10'=>'匿名','20'=>'公开'];
        return $status[$value];
    }

    public function getIdentityTypeAttr($value)
    {
        $status = ['10'=>'游客','20'=>'工作人员'];
        return $status[$value];
    }

    public function getProposeTypeAttr($value)
    {
        $status = ['10'=>'感谢','20'=>'建议','30'=>'曝光','40'=>'咨询','50'=>'投诉','60'=>'监督'];
        return $status[$value];
    }

    public static  function getList($user_id,$status,$page,$type){
        $info=self::where('user_id',$user_id)->order('createtime', 'desc');
        if(!empty($type)){
            $info->where('type', $type);
        }
        switch ($status) {
            case '10':
                $info->where('status', 10);
                break;
            case '20':
                $info->where('status', 20);
                break;
        }
        $list=$info->paginate(15, false, ['page' => $page]);

        return $list;
    }

    public static  function getAnonymityList($status,$page,$type){
        $info=self::where('is_anonymity',20)->order('createtime', 'desc');
        if(!empty($type)){
            $info->where('type', $type);
        }
        switch ($status) {
            case '10':
                $info->where('status', 10);
                break;
            case '20':
                $info->where('status', 20);
                break;
        }
        $list=$info->paginate(15, false, ['page' => $page]);

        return $list;
    }

    public static  function add($data,$user_id){
        $data['order_no']=time().rand(10,6551123);
        $data['user_id']=$user_id;
        $data['createtime']=time();
        $info=new self();
        return $info->save($data);
    }

    public static  function details($id){

        return self::where('id',$id)->find();

    }



}
